package com.sun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.dao.RoomTypeMapper;
import com.sun.pojo.RoomType;
import com.sun.service.RoomTypeService;
import com.sun.utils.DataGridViewResult;
import com.sun.vo.RoomTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoomTypeServiceImpl implements RoomTypeService {

    @Autowired
    private RoomTypeMapper roomTypeMapper;

    public DataGridViewResult findAll(RoomTypeVo roomTypeVo) {
        PageHelper.startPage(roomTypeVo.getPage(),roomTypeVo.getLimit());
        List<RoomType> all = roomTypeMapper.findAll(roomTypeVo);
        PageInfo<RoomType> pageInfo = new PageInfo<RoomType>(all);
        return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
    }

    public int addRoomType(RoomType roomType) {
        return roomTypeMapper.addRoomType(roomType);
    }

    public List<RoomType> initRoomSelectRoomType() {
        return roomTypeMapper.findAll(null);
    }

    public List<RoomType> initRoomTypeSelectForHome() {
        return roomTypeMapper.initRoomType();
    }

    public RoomType findById(int id) {
        return roomTypeMapper.findById(id);
    }

    public int updateRoomType(RoomType roomType) {
        return roomTypeMapper.updateRoomType(roomType);
    }
}
